package com.cloud.clouduser.security.wareable;

import com.cloud.clouduser.dao.UserResponstity;
import com.cloud.clouduser.security.base.SecurityUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

/**
 * @Aurher: QiaoHang
 * @Description:
 * @Data: 2019/9/24 9:28
 * @Modified By:
 */
@Component
public class WareAbleUserDetailsService implements UserDetailsService {
    @Autowired
    UserResponstity userResponstity;

    @Autowired
    PasswordEncoder passwordEncoder;

    /**
     * 用户认证方法
     * @param username
     * @return
     * @throws UsernameNotFoundException
     */
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //查数据库
        Collection<? extends GrantedAuthority> authorities = Collections.singleton(new SimpleGrantedAuthority("SYSTEM"));
        String encode = passwordEncoder.encode("00012");
//        UserDetails userDetails=new SecurityUser(username,encode,Arrays.asList(new String[]{"user","admin","system"}));
        UserDetails userDetails=new SecurityUser(username,encode);
        return userDetails;
    }

}
